import pypyodbc

conn = pypyodbc.win_connect_mdb('C:\\Users\\Administrator\\Desktop\\15\\demo\\student.mdb')
cur = conn.cursor()
sql='create table course(cid VARCHAR(25) PRIMARY KEY, cname VARCHAR(25), score int)'
cur.execute(sql)

print('创建了课程表：编号、名称、学分\n');

sql = "insert into course values('NW2001','Java程序设计',4)"
cur.execute(sql)
sql = "insert into course values('SU1001','Python编程技术',2)"
cur.execute(sql)

print('插入了两条记录\n');

cur.execute('select * from course')
rows = cur.fetchall()
for row in rows:
	print(row) 

print()
	
sql = "update course set cname='Python程序设计' where cid='SU1001'"
cur.execute(sql)

print('修改了课程su1001的名称为“Python程序设计”\n');

cur.execute('select * from course')
rows = cur.fetchall()
for row in rows:
	print(row) 

cur.commit()
conn.close()
